﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NorthwindLinq
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = Enumerable.Range(0, 10);
            var y = x.Select(n => n * n);



            using (var db = new Entities())
            {
                var customerQuery = (from c in db.Customers
                            where c.City == "Berlin"
                            select c).FirstOrDefault();

                //var orderQuery = from o in customerQuery.Orders
                //                 orderby o.OrderDate
                //                 orderby o.ShipAddress
                //                 select new { Name = o.ShipAddress };

                //db.Products.Add(new Product() {
                //    Category = new Category() { }
                //});


                var customer = db.Customers.Where((c) => c.City == "Berlin").FirstOrDefault();

                if(customer != null)
                {
                    var sortedOrders = customer.Orders.
                        OrderBy(o => o.OrderDate).
                        OrderBy(o => o.ShipCity);

                    foreach (var order in sortedOrders)
                    {
                        Console.WriteLine("{0} {1}", order.OrderDate, order.ShipCity);
                    }
                }

                
            }

            Console.ReadKey();
        }
    }
}
